﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using dzs.Model;
namespace dzs.BLL
{
	/// <summary>
	/// inventory
	/// </summary>
	public partial class inventory
	{
		private readonly dzs.DAL.inventory dal=new dzs.DAL.inventory();
		public inventory()
		{}
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetinventoryRecordCount(string strWhere)
        {
            return dal.GetinventoryRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetinventoryListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetinventoryListByPage(strWhere, orderby, startIndex, endIndex);
        }
        public bool Updatenums(int mid, int spid, decimal nums)
        {
            bool rb = false;
            decimal innums = dal.Getnums(mid, spid);
            if (innums >= nums)
                rb = dal.Updatenums(mid, spid, nums);
            return rb;
        }

        public DataSet Getmatralbyspid(int spid)
        {
            return dal.Getmatralbyspid(spid);
        }
        public bool Updatenums(int inid, decimal newnum)
        {
            return dal.Updatenums(inid, newnum);
        }
        public bool Updateadjust(int outid, int inid)
        {
            return dal.Updateadjust(outid, inid);
        }
        public bool Updateadjustbymid(int outid, int inid, string mid,int status)
        {
            return dal.Updateadjustbymid(outid, inid, mid,status);
        }
        public DataSet Gettakestore(string strWhere)
        {
            return dal.Gettakestore(strWhere);
        }
        public DataSet Getinventory(string strWhere)
        {
            return dal.Getinventory(strWhere);
        }
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int inid)
		{
			return dal.Exists(inid);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(dzs.Model.inventory model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(dzs.Model.inventory model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int inid)
		{
			
			return dal.Delete(inid);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string inidlist )
		{
			return dal.DeleteList(inidlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public dzs.Model.inventory GetModel(int inid)
		{
			
			return dal.GetModel(inid);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public dzs.Model.inventory GetModelByCache(int inid)
		{
			
			string CacheKey = "inventoryModel-" + inid;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(inid);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (dzs.Model.inventory)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<dzs.Model.inventory> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<dzs.Model.inventory> DataTableToList(DataTable dt)
		{
			List<dzs.Model.inventory> modelList = new List<dzs.Model.inventory>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				dzs.Model.inventory model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
         /// <summary>
        /// 获取项目物料累计库存量
        /// </summary>
        public DataSet GetSumNumsProjectInventory(string strWhere)
        {
            return dal.GetSumNumsProjectInventory(strWhere);
        }
         /// <summary>
        /// 获取应急出库列表（剩余数量 = 库存量-已申请出库计划未出库量）
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public DataSet GetMaterialInventoryOutStorageList(string where)
        {
            return dal.GetMaterialInventoryOutStorageList(where);
        }
         /// <summary>
        /// 获取项目物料库存入库数量
        /// </summary>
        public DataSet GetListMaterialInventoryInstore(string strWhere)
        {
            return dal.GetListMaterialInventoryInstore(strWhere);
        }
        /// <summary>
        /// 获取库存,real_count=库存数量（当前的库存量）-已申请的出库数量（不包括已出库的数量(deal_status<>'已出库')），当real_counts值为Null时，代表此条物料未申请出库，应以库存(库存表inventory表的nums)数量计算（ventroyNums）
        /// </summary>
        public DataSet GetMaterialVentoryInfo(string proid,string where)
        {
            return dal.GetMaterialVentoryInfo(proid,where);
        }

        /// <summary>
        /// 获取项目物料库存量
        /// </summary>
        public DataSet GetListMaterialInventoryProject(string strWhere)
        {
            return dal.GetListMaterialInventoryProject(strWhere);
        }
		#endregion  ExtensionMethod
	}
}

